package com.zbxx.practice.designpattern.watch;

import com.zbxx.practice.designpattern.watch.jdk.JdkConcreteObserver;
import com.zbxx.practice.designpattern.watch.jdk.JdkSubject;
import com.zbxx.practice.designpattern.watch.normal.ConcreteObserver;
import com.zbxx.practice.designpattern.watch.normal.ConcreteSubject;
import com.zbxx.practice.designpattern.watch.normal.Observer;
import com.zbxx.practice.designpattern.watch.normal.Subject;

/**
 * @author 万仁杰
 * @date 2019/06/03
 */
public  class Main {


    /**
     * 可以理解为 一对多 一方改变 通知多方uodate
     * @param args
     */

    public static void main(String[] args) {
        /**
         * 通用观察者
         */
        Subject subject = new ConcreteSubject();
        ((ConcreteSubject) subject).setContent("天气不错");

        Observer observer = new ConcreteObserver();
        ((ConcreteObserver) observer).setThings("吃饭");
        ((ConcreteObserver) observer).setUsername("亚索");

        Observer observer2 = new ConcreteObserver();
        ((ConcreteObserver) observer2).setThings("打游戏");
        ((ConcreteObserver) observer2).setUsername("锐雯");

        subject.add(observer);
        subject.add(observer2);
        subject.notifyObservers();

        /**
         * jdk
         */
        JdkSubject jdkSubject = new JdkSubject();
        JdkConcreteObserver jdkObserver = new JdkConcreteObserver();
        jdkObserver.setUsername("EZ");
        JdkConcreteObserver jdkConcreteObserver = new JdkConcreteObserver();
        jdkConcreteObserver.setUsername("寒冰");
        jdkSubject.addObserver(jdkConcreteObserver);
        jdkSubject.addObserver(jdkObserver);
        jdkSubject.setContent("开始装逼");
    }

}
